<?php
 require_once 'loginSuccess.php';
	
 $username = $_SESSION['username'];

function getAlbumCover($albumId) {
	global $dbConnection;
	$query = "Select name
			from images
			where albumId = $albumId limit 1;";
	$statement = $dbConnection->execute($query);
	$coverName = $statement->fetch_row();
	return $coverName;
}

function displayAlbums($statement) {
	echo "<table><tr>";
	$i = 1;
	while($albumArr = $statement->fetch_assoc()) {
		$albumId = $albumArr['albumId'];
		$albumName = $albumArr['name'];
		$coverName = getAlbumCover($albumId);
		$cover = $coverName[0];
		echo "<td><a href='album.php?id=$albumId'><img src='images/$cover' style='width:100px; height:100px;'/></a><br />$albumName</td>";
		if($i % 5 == 0) {
			echo "</tr><tr>";
		}
		$i++;
	}
	echo "</tr></table>";
}

$albumArr = $dbConnection->getUserAlbums();
displayAlbums($albumArr);
?>